package com.zyd.blog.personal.controller;

import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.homeart.service.BackstageReportTypeService;
import com.zyd.blog.homeart.util.ResponseObject;
import com.zyd.blog.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liusongqi
 * @since 2020-03-18
 */
@RestController
@RequestMapping("/backstageReport")
public class BackstageReportTypeController {
    private final Logger logger = LoggerFactory.getLogger(BackstageReportTypeController.class);
    @Autowired
    private BackstageReportTypeService backstageReportTypeService;

    /**     举报信息 可选择
     *
     */
    @RequestMapping(value = "/reportTypeAll", method = RequestMethod.POST)
    public PageResult reportTypeAll(int page, int count) {
        logger.info("/backstageReport/reportTypeAll 举报信息 可选择,page={},count={}",page,count);
        ResponseObject ob = new ResponseObject();
        PageResult pageResult = new PageResult();
        return backstageReportTypeService.listAll(page,count);
//        ob.setCode(0);
//        ob.setData(backstageReportTypeService.listAll(page,count));
//        return ob;
    }


    /**    修改 举报信息 可选择
     *
     */
    @RequestMapping(value = "/updateReportType", method = RequestMethod.POST)
    public ResponseVO updateReportType(String id, String content) {
        logger.info("/backstageReport/updateReportType 修改 举报信息 可选择,id={},content={}",id,content);

        return ResultUtil.success(null, backstageReportTypeService.updateReportType(id,content));
    }
    /**    根据修改找到内容
     *
     *
     */

    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public ResponseVO get(String id) {
        return ResultUtil.success(null, backstageReportTypeService.get(id));
    }
    /**     删除 举报信息 可选择
     *
     */
    @RequestMapping(value = "/deleteReportType", method = RequestMethod.POST)
    public ResponseVO deleteReportType(int[] ids) {
        logger.info("/backstageReport/deleteReportType 删除 举报信息 可选择,ids={}",ids);
        for (int id : ids) {
            backstageReportTypeService.deleteReportType(id);
        }
        return ResultUtil.success("成功删除 [" + ids.length + "] 个文章类型");
    }

    /**     新增
     *
     */
    @RequestMapping(value = "/addReportType", method = RequestMethod.POST)
    public ResponseVO addReportType(String content) {
        logger.info("/backstageReport/addReportType 新增,content={}",content);

        try {
            backstageReportTypeService.addReportType(content);
            return ResultUtil.success("成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("error");
        }
    }

}
